package j04hashmap;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class J3for {
    public static void main(String[] args) {
        Map<String,String> m1 = new HashMap<>();
        m1.put("name","阿凡达");//avatar
        m1.put("type","科幻");
        System.out.println("m1 = " + m1);

        //keys
        Set<String> keys = m1.keySet();
        for (String key : keys) {
            System.out.println(key);
            System.out.println(m1.get(key));
            System.out.println("===");
        }
        System.out.println("**********");
        Set<Map.Entry<String,String>> entrySet = m1.entrySet();
        for (Map.Entry<String,String> entry:entrySet) {
            System.out.println("key="+entry.getKey());
            System.out.println("value="+entry.getValue());
            System.out.println("==");
        }
    }
}

class Cat{
    String name;

    public Cat(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                '}';
    }
}

class CatTest{
    public static void main(String[] args) {
//        Map<String,Cat> m1 = new HashMap<>();
        Map<String,Cat> m1 = new LinkedHashMap<>();//有序
        m1.put("yellow",new Cat("小黄猫"));
        m1.put("white",new Cat("小白猫"));
        m1.put("black",new Cat("小黑猫"));

        Set<String> keys = m1.keySet();
        for (String key :
                keys) {
            System.out.println("key="+key);
            System.out.println("value="+m1.get(key));
        }
    }
}
